

package cn.shengchao.examstar.comment.ohs.local.message;

import cn.shengchao.examstar.comment.acl.ports.repositories.message.CommentListDto;
import lombok.Data;

import java.util.List;

@Data
public class CommentStatistics {
    private List<CommentListDto> commentDtoList;
    private int total;
    //平均分
    private int averageScore;
    //5星人数
    private int fiveStarCount;
    //4星人数
    private int fourStarCount;
    //3星人数
    private int threeStarCount;
    //2星人数
    private int twoStarCount;
    //1星人数
    private int oneStarCount;

    public CommentStatistics(List<CommentListDto> commentDtoList) {
        this.commentDtoList = commentDtoList;
        this.total = (int)commentDtoList.stream().map(CommentListDto::getStudentName).distinct().count();
        this.averageScore = (int)commentDtoList.stream().mapToDouble(CommentListDto::getScore).average().orElse(0);
        this.fiveStarCount = (int)commentDtoList.stream().filter(item -> item.getScore() == 5.0).count();
        this.fourStarCount = (int)commentDtoList.stream().filter(item -> item.getScore() == 4.0).count();
        this.threeStarCount = (int)commentDtoList.stream().filter(item -> item.getScore() == 3.0).count();
        this.twoStarCount = (int)commentDtoList.stream().filter(item -> item.getScore() == 2.0).count();
        this.oneStarCount = (int)commentDtoList.stream().filter(item -> item.getScore() == 1.0).count();
    }
}
